package com.itheima.health.mapper;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;
import java.util.Map;

public interface BusinessMapper {

    @Select("select count(1) from t_member where REGTIME=#{reportDate}")
    int findNewMember(Date reportDate);

    @Select("select count(1) from t_member")
    int findAllMember();

    @Select("select count(1) from t_member where REGTIME between #{weekone} and #{reportDate}")
    int findNewMemberOnThisWeek(@Param("weekone") Date weekone,@Param("reportDate") Date reportDate);

    @Select("select count(1) from t_member where REGTIME between #{monthone} and #{reportDate}")
    int findNewMemberOnThisMonth(@Param("monthone") Date monthone,@Param("reportDate") Date reportDate);

    @Select("select count(1) from t_order where ORDERDATE=#{reportDate}")
    int findTodayOrderNumber(Date reportDate);

    @Select("select count(1) from t_order where ORDERDATE=#{reportDate} and ORDERSTATUS='已到诊'")
    int findTodayVisitsNumber(Date reportDate);

    @Select("select count(1) from t_order where ORDERDATE between #{weekone} and #{reportDate}")
    int findThisWeekOrderNumber(@Param("weekone") Date weekone,@Param("reportDate") Date reportDate);

    @Select("select count(1) from t_order where ORDERDATE between #{weekone} and #{reportDate} and ORDERSTATUS='已到诊'")
    int findThisWeekVisitsNumber(@Param("weekone") Date weekone,@Param("reportDate") Date reportDate);

    @Select("select count(1) from t_order where ORDERDATE between #{monthone} and #{reportDate}")
    int findthisMonthOrderNumber(@Param("monthone") Date monthone,@Param("reportDate") Date reportDate);

    @Select("select count(1) from t_order where ORDERDATE between #{monthone} and #{reportDate} and ORDERSTATUS='已到诊'")
    int findthisMonthVisditsNumber(@Param("monthone") Date monthone,@Param("reportDate") Date reportDate);

    @Select("select ts.name,count(1) as setmeal_count,ts.remark " +
            "from t_order tor ,t_setmeal ts " +
            "where tor.SETMEAL_ID=ts.ID " +
            "group by tor.SETMEAL_ID " +
            "order by count(1) desc " +
            "limit 0,5")
    List<Map<String, Object>> findHotSetmeal();

    @Select("select count(1) from t_order")
    int findSumSetmeal();
}
